import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
import ElementUI from "element-ui";
import axios from "axios";

import "element-ui/lib/theme-chalk/index.css";

Vue.use(ElementUI);

//axios.defaults.baseURL = "http://127.0.0.1:3000"; //编译前要注释掉测试url
Vue.prototype.axios = axios;

Vue.config.productionTip = false;

var app = new Vue({
  data() {
    return {
      permitionvalue: ""
    };
  },
  router,
  store,
  render: h => h(App),
  methods: {
    getpermition() {
      this.axios
        .get("/getloggedpermition", {
          params: {
            user: "liuweichang"
          }
        })
        .then(response => {
          if (response.data.permition == 1) {
            //this.route.push("/about");
            return (this.permitionvalue = response.data);
          }
          this.$message({
            message: "无此权限",
            type: "warning"
          });
        })
        .catch(function() {
          app.$message.error("抱歉！发生了未知错误");
        });
    }
  }
}).$mount("#app");
router.beforeEach((to, from, next) => {
  if (to.name == "about") {
    app.getpermition();
    if (app.permitionvalue.permition != 1) {
      next("/");
    } else {
      next();
    }
  } else {
    next();
  }
});
